package com.epic.followup.interceptor;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerInterceptor;

/**
 * @author : zx
 * @version V1.0
 */
public class WechatPatientInterceptor implements HandlerInterceptor {

    private org.slf4j.Logger log = LoggerFactory.getLogger(this.getClass());

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {

        log.info("[拦截]" + new Date().toString() + ": ");
        log.info(request.getRequestURI());

        // session中存在电话号码，说明之前登录过
        HttpSession session = request.getSession();
        if(session.getAttribute("phone") == null){
            response.sendError(401);
            return false;
        }

        return true;
    }
}
